/* 这是一个 product router */
import React      from "react";
import {
  Route,
  Switch,
  Redirect
} from 'react-router-dom'

// 页面
import ProductList       from 'page/product/index/index.jsx';
import ProductSave       from 'page/product/index/save.jsx';
import ProductDetail     from 'page/product/index/detail.jsx';
import CategoryList      from 'page/product/category/index.jsx';
import CategoryAdd      from 'page/product/category/add.jsx';

// 做一个 product 的分路由
// '/product/save/:pid?' 后面加 ？ 表示这个是可选的属性，就是加或者不加 pid 都是 ProductSave组件
class ProductRouter extends React.Component{
  render(){
    return (
      <Switch>
        <Route path='/product/index' component={ProductList} />
        <Route path='/product/save/:pid?' component={ProductSave} />
        <Route path='/product/detail/:pid' component={ProductDetail} />
        <Route path='/product-category/index/:categoryId?' component={CategoryList} />
        <Route path='/product-category/add' component={CategoryAdd} />
        <Redirect exact from='/product' to="/product/index" />
        <Redirect exact from='/product-category' to="/product-category/index" />
      </Switch>
    );
  }
}

export default ProductRouter;
